package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL执行DML操作--UPDATE
 */
public class JDBCDemo10 {
    public static void main(String[] args) {
        try (Connection c=DBUtil.getConnection();)
        {
            /*
            UPDATE userinfo
            SET password=?,username=?,age=?
            WHERE id=16;
             */
            String s="UPDATE userinfo \n" +
                    "            SET password=?,username=?,age=?\n" +
                    "            WHERE id=16; ";
            PreparedStatement ps= c.prepareStatement(s);
            ps.setString(1,"258");
            ps.setString(2,"阿兰");
            ps.setInt(3,26);
            int a=ps.executeUpdate();
            System.out.println(a>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
